﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class User_Edit_AvatarController : UserController
    {
        [Authorize]
        [HttpGet]
        public IActionResult Get(string imgurl)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                return Ok(new { status = 0, msg = "温馨提示：用户尚未登录或已超时！" });
            }
            //检查输入的旧密码
            if (string.IsNullOrEmpty(imgurl))
            {
                return Ok(new { status = 0, msg = "温馨提示：先上传头像路径！" });
            }
            var sysConfig = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            _users.UpdateField(model.id,"avatar='"+imgurl.Replace(sysConfig.weburl, "")+"'");
            return Ok(new { status = 1, msg = "头像修改成功！" });
        }
    }
}